//
//  ShareCell.m
//  wtshoppingcite
//
//  Created by TW on 15-3-26.
//  Copyright (c) 2015年 TW. All rights reserved.
//

#import "ShareCell.h"

@implementation ShareCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews{
    
    _iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 40, 40)];
    _iconImageView.layer.cornerRadius = 20;
    _iconImageView.image = [UIImage imageNamed:@""];
    _iconImageView.clipsToBounds = YES;
    [self.contentView addSubview:_iconImageView];
    
    _nickNameLable = [self createLabelWithFrame:CGRectMake(_iconImageView.right +10, 5, 200, 30) text:@"" font:16 textAli:NSTextAlignmentLeft textColor:MAIN_BLACK_COLOR];
    [self.contentView addSubview:_nickNameLable];
    
    _dateLable = [self createLabelWithFrame:CGRectMake(_nickNameLable.left, _nickNameLable.bottom, 120, 18) text:@"" font:12 textAli:NSTextAlignmentLeft textColor:UIColorFromRGB(0x9fa0a0)];
    [self.contentView addSubview:_dateLable];
    
    _textLable = [self createLabelWithFrame:CGRectMake(_dateLable.left, _dateLable.bottom, kWidth-70, 40) text:@"" font:13 textAli:NSTextAlignmentLeft textColor:UIColorFromRGB(0x9fa0a0)];
    _textLable.numberOfLines = 0;
    [self.contentView addSubview:_textLable];
    
    _contentImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
    [self.contentView addSubview:_contentImageView];
    
    _titleLabel = [self createLabelWithFrame:CGRectZero text:@"" font:12 textAli:NSTextAlignmentLeft textColor:MAIN_BLUE_COLOR];
    [self.contentView addSubview:_titleLabel];
    
    _pinglunView = [[UIImageView alloc]initWithFrame:CGRectZero];
    _pinglunNum.left = self.width - 85;
    [self.contentView addSubview:_pinglunView];
    
    _pinglunNum = [self createLabelWithFrame:CGRectZero text:@"" font:12.0f textAli:NSTextAlignmentCenter textColor:MAIN_BLUE_COLOR];
    [self addSubview:_pinglunNum];
    
    _zuanView = [[UIImageView alloc]initWithFrame:CGRectZero];
    [self.contentView addSubview:_zuanView];
   
    
    _zuanNum =[self createLabelWithFrame:CGRectZero  text:@"" font:12.0f textAli:NSTextAlignmentCenter textColor:MAIN_BLUE_COLOR];
    [self.contentView addSubview:_zuanNum];
    
}

-(void)setShareModel:(ShareModel *)shareModel{
    if (_shareModel != shareModel) {
        _shareModel =shareModel;
        
        if ([shareModel.smallImgPath isEqualToString:@""] || [shareModel.smallImgPath isEqualToString:@"(null)"]) {
            
            _titleLabel.frame = CGRectMake(_textLable.left, _textLable.bottom, 160, 20);
            _pinglunView.frame = CGRectMake(_titleLabel.right,_textLable.bottom, 20, 20);
            _pinglunNum.frame = CGRectMake(_pinglunView.right, _textLable.bottom, 20, 20);
            _zuanView.frame = CGRectMake(_pinglunNum.right, _textLable.bottom, 18, 18);
            _zuanNum.frame = CGRectMake(_zuanView.right, _textLable.bottom, 20, 20);
            _contentImageView.image = nil;

            
        }else{
            
            _iconImageView.frame = CGRectMake(10, 10, 40, 40);
            _nickNameLable.frame = CGRectMake(_iconImageView.right +10, 5, 200, 30);
            _dateLable.frame = CGRectMake(_nickNameLable.left, _nickNameLable.bottom, 120, 18);
            _textLable.frame = CGRectMake(_dateLable.left, _dateLable.bottom, kWidth-70, 40);
            _contentImageView.frame = CGRectMake(_textLable.left, _textLable.bottom, 100, 100);
            _titleLabel.frame = CGRectMake(_contentImageView.left, _contentImageView.bottom, 160, 20);
            _pinglunView.frame = CGRectMake(_titleLabel.right,_contentImageView.bottom, 20, 20);
            _pinglunNum.frame = CGRectMake(_pinglunView.right, _pinglunView.top, 20, 20);
            _zuanView.frame = CGRectMake(_pinglunNum.right, _pinglunNum.top, 18, 18);
            _zuanNum.frame = CGRectMake(_zuanView.right, _zuanView.top, 20, 20);
            
            [_contentImageView setImageWithURL:[NSURL URLWithString:_shareModel.smallImgPath] placeholderImage:[UIImage imageNamed:@"touxiang_org"]];
        }
        
        _nickNameLable.text =CHECK_ISNULL(self.shareModel.nickName);
        
        _dateLable.text = _shareModel.createTime;
        _textLable.text = _shareModel.content;
        
        
       [_iconImageView setImageWithURL:[NSURL URLWithString: _shareModel.imgPath] placeholderImage:[UIImage imageNamed:@"touxiang_org"]];
        
         NSString *title;
         if([_shareModel.type isEqual:@"1"]){
             title =@"投诉" ;
         }else if([_shareModel.type isEqual:@"2"]){
             title = @"表扬";
         }else if([_shareModel.type isEqual:@"3"]){
             title = @"订单分享";
         }else if([_shareModel.type isEqual:@"4"]){
             title = @"好人好事";
         }else if([_shareModel.type isEqual:@"5"]){
             title = @"帮帮忙";
         }else if([_shareModel.type isEqual:@"6"]){
             title = @"跳蚤市场";
         }else if([_shareModel.type isEqual:@"7"]){
             title = @"美食";
         }else if([_shareModel.type isEqual:@"8"]){
             title = @"其它";
         }else if([_shareModel.type isEqual:@"9"]){
             title = @"其它";
         }

        _titleLabel.text = [NSString stringWithFormat:@"标签:%@",title];
     
        NSString *parisenum;
        if(_shareModel.praiseNumber == nil || [_shareModel.praiseNumber isEqual:[NSNull null]] || [_shareModel.praiseNumber isEqualToString:@"(null)"]){
            parisenum = @"0";
        }else{
            parisenum = _shareModel.praiseNumber;
        }
        
        
        NSString *pinglun;
        if(_shareModel.commentNumber == nil || [_shareModel.commentNumber isEqual:[NSNull null]] || [_shareModel.commentNumber isEqualToString:@"(null)"]){
            pinglun = @"0";
        }else{
            pinglun = _shareModel.commentNumber;
        }

        _pinglunView.image =[UIImage imageNamed:@"qipao_pingjia"];
        _pinglunNum.text = pinglun;
        _zuanView.image = [UIImage imageNamed:@"zuan_org"];
        _zuanNum.text = parisenum;
    }
}

-(UILabel*)createLabelWithFrame:(CGRect)frame text:(NSString*)text font:(int)font textAli:(NSTextAlignment)alig textColor:(UIColor*)tc{
    if(text == nil)
        text = @"";
    UILabel* label = [[UILabel alloc] initWithFrame:frame];
    label.text = text;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = alig;
    label.textColor = tc;
    label.numberOfLines = 0;
    label.backgroundColor = [UIColor clearColor];
    return label;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)awakeFromNib {
    // Initialization code
}

@end
